package com.qcloud.cos.request;

import com.qcloud.cos.common_utils.CommonParamCheckUtils;
import com.qcloud.cos.exception.ParamException;

import java.io.InputStream;

/**
 * Created by yanwc on 2016/8/27.
 */
public class UploadSliceFileStreamRequest extends UploadFileStreamRequest {
    // 默认分片大小1MB
    private static final int DEFAULT_SLICE_SIZE = 1024 * 1024;

    public int getSliceSize() {
        return sliceSize;
    }

    public void setSliceSize(int sliceSize) {
        this.sliceSize = sliceSize;
    }

    private int sliceSize = DEFAULT_SLICE_SIZE;

    public UploadSliceFileStreamRequest(UploadFileStreamRequest request) {
        super(request.getBucketName(), request.getCosPath(), request.getStream(),request.getFileName());
        this.setInsertOnly(request.getInsertOnly());
    }
    public UploadSliceFileStreamRequest(String bucketName, String cosPath,InputStream stream, int sliceSize,String fileName) {
        super(bucketName, cosPath, stream,fileName);
        this.sliceSize = sliceSize;
    }

    @Override
    public void check_param() throws ParamException {
        super.check_param();
        CommonParamCheckUtils.AssertLegalSliceSize(this.sliceSize);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        sb.append(", sliceSize:").append(this.sliceSize);
        return sb.toString();
    }
}
